package com.zyz.K_集合.Map接口一HashMap.练习;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author: vick
 * @Date: 2025/3/31
 * @Description:
 * @version: 1.0
 */
public class Demo4 {
    public static void main(String[] args) {
        HashMap<String, Employee> employees = new HashMap<>();
        employees.put("001", new Employee("aa","研发", 10000));
        employees.put("002", new Employee("bb","前端", 80000));
        employees.put("003", new Employee("cc","测试", 5000));
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1查询：");
            System.out.println("2更新：");
            System.out.println("3退出：");
            int choice = scanner.nextInt();
            scanner.nextLine();
            switch (choice) {
                case 1:
                    System.out.println("输入员工工号：");
                    String employeeId = scanner.nextLine();
                    if (employees.containsKey(employeeId)) {
                        System.out.println("员工信息：" + employees.get(employeeId));
                    }else {
                        System.out.println("未找到该员工信息");
                    }
                    break;
                case 2:
                    System.out.println("输入员工工号：");
                    String employeeIdUpdate = scanner.nextLine();
                    if (employees.containsKey(employeeIdUpdate)) {
                        System.out.println("请输入新姓名：");
                        String newName = scanner.next();
                        System.out.println("请输入新部门：");
                        String newDep = scanner.next();
                        System.out.println("请输入新薪资：");
                        double newSalary = scanner.nextDouble();
                        Employee employee = new Employee(newName, newDep, newSalary);
                        employees.put(employeeIdUpdate, employee);
                        System.out.println("员工信息更新成功");
                    }else {
                        System.out.println("未找到该员工信息");
                    }
                    break;
                case 3:
                    System.out.println("退出成功");
                    scanner.close();
                    return;
                default:
                    System.out.println("无效输入");
            }
        }
    }
}
